#include "propertiesdialog.h"
#include <QDebug>


PropertiesDialog::PropertiesDialog(QWidget * parent) : KeyControllableMenu(parent) {
    QGridLayout * propertiesLayout = new QGridLayout();
    QHBoxLayout * buttonsLayout = new QHBoxLayout();    
    QWidget * propertiesWidget=new QWidget(this);

    artistLineEdit = new QLineEdit(this);
    titleLineEdit = new QLineEdit(this);
    descriptionLineEdit = new QLineEdit(this);
    okButton = new Button(QIcon(":/imgs/3F00Button_Ok.png"),"",this);
    cancelButton = new Button(QIcon(":/imgs/3F00Button_Cancel.png"),"",this);
    okButton->setIconSize(QSize(103,60));
    cancelButton->setIconSize(QSize(103,60));

    buttonsLayout->addWidget(cancelButton);
    buttonsLayout->addWidget(okButton);
    propertiesLayout->addWidget(new QLabel("Artist:"),0,0);
    propertiesLayout->addWidget(new QLabel("Title:"),1,0);
    propertiesLayout->addWidget(new QLabel("Description:"),2,0);
    propertiesLayout->addWidget(artistLineEdit,0,1);
    propertiesLayout->addWidget(titleLineEdit,1,1);
    propertiesLayout->addWidget(descriptionLineEdit,2,1);
    propertiesLayout->addLayout(buttonsLayout,3,0,1,2);

    propertiesWidget->setLayout(propertiesLayout);
    setLayout(new QVBoxLayout());
    layout()->addWidget(propertiesWidget);

    buttonsLayout->setDirection(QBoxLayout::RightToLeft);
    setMinimumSize(400,300);
    setStyleSheet("PropertiesDialog { background: rgb(0, 0, 0); color: rgb(255,255,255); } .Button{background: rgb(0, 0, 0);border:0px;} .Button:pressed {background: qlineargradient(spread:pad, x1:0.07, y1:0.153409, x2:1, y2:1, stop:0 rgba(0, 0, 0, 50), stop:1 rgba(255, 255, 255, 70)); border: 1px solid rgba(255, 255, 255, 200);} .QWidget {background: rgb(0, 0, 0);border: 1px solid white; border-radius: 10px;} .QLineEdit {color: rgb(0,0,0)}");

    this->move(QPoint((QApplication::desktop()->width()-this->width())/2,(QApplication::desktop()->height()-this->height())/2));

    connect(artistLineEdit,SIGNAL(returnPressed()),this,SLOT(okSelected()));
    connect(titleLineEdit,SIGNAL(returnPressed()),this,SLOT(okSelected()));
    connect(descriptionLineEdit,SIGNAL(returnPressed()),this,SLOT(okSelected()));
    connect(okButton,SIGNAL(clicked()),this,SLOT(okSelected()));
    connect(cancelButton,SIGNAL(clicked()),this,SLOT(cancelSelected()));

}

void PropertiesDialog::show(MediaFile * file) {
    currentFile = file;
    artistLineEdit->setText(file->artist);
    titleLineEdit->setText(file->title);
    descriptionLineEdit->setText(file->description);
    QWidget::show();
    artistLineEdit->setFocus();
    artistLineEdit->selectAll();
}

void PropertiesDialog::closeEvent(QCloseEvent *event) {    
    QWidget::closeEvent(event);
    emit closed(0);
}

void PropertiesDialog::okSelected() {
    hide();
    currentFile->artist = artistLineEdit->text();
    currentFile->title = titleLineEdit->text();
    currentFile->description = descriptionLineEdit->text();
    emit closed(currentFile);
}

void PropertiesDialog::cancelSelected() {
    hide();
    emit closed(0);
}




